<?php
namespace app\index\controller;

use think\Request;

class Rong extends CheckMember
{
    /**
     * 融云
     * @return \think\response\View
     */
    public function index()
    {
        // 获取用户融云信息
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_member_rong_info', $param);
        if(Request::instance()->isAjax()) {
            return json($data['data']);
        }
//       dump($data); exit;
        $this->assign('data', $data['data']);

        // 获取用户好友列表
        $friend = $this->local_invoke_api('get_member_rong_friend', $param);
//        dump($friend);exit;
        $this->assign('friend', $friend['data']);
//
//        // 获取对话记录
//        $data = $this->local_invoke_api('get_member_rong_dialogue', $param);
//        $this->assign('list', $data['data']);

        return view('layim');
    }

    /**
     * 融云消息发送记录
     * @return \think\response\View
     */
    public function save_rong_msg() {
        $param = input('param.');
//        dump($param);exit;
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('save_rong_msg', $param);
        return json($data);
    }

    // 创建单聊页面
    public function create_chat() {
        // 获取用户融云信息
        $param = input('param.');
        $param['member_id'] = session('member_id');
        if ($param['type'] == 'group') {
            $data = $this->local_invoke_api('get_group_rong_info', $param);
        } else {
            $data = $this->local_invoke_api('get_member_rong_info', $param);
        }

        $this->assign('data', $data['data']);
        return view();
    }

    public function get_group_members() {
        $param = input('param.');
        $data = $this->local_invoke_api('get_group_members', $param);
        return json($data['data']);
    }

    public function get_msg_list() {
        $param = input('param.');
        $param['member_id'] = session('member_id');
        $data = $this->local_invoke_api('get_msg_list', $param);
        return json($data['data']);
    }

    public function upload_image() {
        $data = \app\api\service\Upload::layim_upload_img();
        if ($data['code'] = 200) {
            return json([
                "code" => 0,
                "msg" => "success",
                "data" => [
                    "src" => $data['path'] . "-100"
                ]
            ]);
        } else {
            return json([
                "code" => 1,
                "msg" => "success",
                "data" => [
                    "src" => ""
                ]
            ]);
        }
    }

    public function text() {
        return view();
    }

}
